package as.myapplication;

import android.Manifest;
import android.support.annotation.NonNull;
import android.support.v4.content.PermissionChecker;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.zhy.m.permission.MPermissions;
import com.zhy.m.permission.PermissionDenied;
import com.zhy.m.permission.PermissionGrant;

public class MainActivity extends AppCompatActivity {
    private Button bnt;
    private static final int REQUECT_CODE_CAMERA = 2;




    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        bnt = (Button) findViewById(R.id.bnt);
        bnt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MPermissions.requestPermissions(MainActivity.this,REQUECT_CODE_CAMERA, Manifest.permission.CAMERA);

            }
        });

    }

    @Override
    public void onRequestPermissionsResult(int requestCode,  String[] permissions,  int[] grantResults) {
        MPermissions.onRequestPermissionsResult(this,requestCode,permissions,grantResults);
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }

    @PermissionGrant(REQUECT_CODE_CAMERA)
    public void requestCameraSuccess(){
        Toast.makeText(this, "申请成功", Toast.LENGTH_SHORT).show();
    }

    @PermissionDenied(REQUECT_CODE_CAMERA)
    public void requestSdcardFailed(){
        Toast.makeText(this, "申请失败", Toast.LENGTH_SHORT).show();
    }

}
